package com.example.accessingdatajpa.controller;

import com.example.accessingdatajpa.pojo.Category;
import com.example.accessingdatajpa.response.RestResponse;
import com.example.accessingdatajpa.service.impl.CategoryServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/app")
public class CategoryController {

    @Autowired
    final private CategoryServiceImpl categoryService;

    public CategoryController(CategoryServiceImpl categoryService) {
        this.categoryService = categoryService;
    }

    //find all categories
    @GetMapping(path = "/allCategories")
    public @ResponseBody RestResponse<List<Category>> findAllCategories(){
        return categoryService.queryAllCategory();
    }

    //add new category
    @PostMapping(path = "/addCategory")
    public @ResponseBody RestResponse<String> addACategory(@RequestBody Category category){
        return categoryService.addOneCategory(category);
    }
}
